<template>
  <a-config-provider :locale="locale">
    <router-view v-if="isActive" />
  </a-config-provider>
</template>

<script lang="ts" setup>
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import zhCN from "ant-design-vue/es/locale/zh_CN";
import {ref, nextTick, provide} from "vue";
import {appinit} from "@/utils/common";

const locale = zhCN;
const isActive = ref(true);
dayjs.locale("zh-cn");

appinit();
const reloadAll = () => {
  isActive.value = false;
  nextTick(() => {
    isActive.value = true;
  });
};
provide("reloadAll", reloadAll);

let beforeUnloadTime = 0;
let gapTime = 0;
let beforeunloadHandler = (e) => {
  beforeUnloadTime = new Date().getTime();
};
let unloadHandler = (e) => {
  gapTime = new Date().getTime() - beforeUnloadTime;
  //判断是窗口关闭还是刷新
  if (gapTime <= 5) {
    //关闭窗口
  } else {
    //刷新
  }
};
window.addEventListener("beforeunload", (e) => beforeunloadHandler(e));
window.addEventListener("unload", (e) => unloadHandler(e));
</script>
